const mysql = require('mysql2');

// 创建数据库连接池
const pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: '123456',
  database: 'hanlinshudian',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

// 添加错误处理
pool.on('error', (err) => {
  console.error('Database error:', err);
  if (err.code === 'PROTOCOL_CONNECTION_LOST') {
    console.log('Database connection was closed.');
  } else {
    throw err;
  }
});

// 导出 promise 包装的连接池
module.exports = pool.promise(); 